********************************************************************************
* Leipziger, L, Aarslew, L, & M. Christensen
* Replication Code for "Do Group-Based Inequalities Feel More Unjust?"
* POQ, 2026
* This code: Fig 1: Dictionary approch - mentioning words from our intergroup dictionary
********************************************************************************
********************************************************************************
clear all
frame rename default data

** Marginal effects (India): 
import excel "data\dictionary_IN.xlsx", sheet("Sheet 1") firstrow clear
encode D, generate(treat)
qui reg race_dum i.treat , rob		
margins, at(treat=(1(1)3))
mat A = r(table)
est store india // for tables
estadd scalar ajr2 = e(r2_a)

** Marginal effects (South Africa)
import excel "data\dictionary_ZA.xlsx", sheet("Sheet 1") firstrow clear
encode D, generate(treat)
qui reg race_dum i.treat , rob			
margins, at(treat=(1(1)3))
mat B = r(table)
est store za // for tables
estadd scalar ajr2 = e(r2_a)


** Marginal effects (USA)
import excel "data\dictionary_US.xlsx", sheet("Sheet 1") firstrow clear
encode D, generate(treat)
drop if treat==4 | treat==5				// Intragroup inequality treatments dropped 
qui reg race_dum i.treat , rob			
margins, at(treat=(1(1)3))
mat C = r(table)
est store us // for tables
estadd scalar ajr2 = e(r2_a)

lab define treat_lb 1 "Baseline" 2 "\forceindent Intergroup ineq." 3 "\forceindent Interpersonal ineq."
lab values treat treat_lb


**making tables SM2 in supplementary analyses
esttab india za us using "output/tableSM2.tex", lab nogap wide tex cells("b(fmt(3))" se(par(`"("' `")"') fmt(3)) p(par(`"["' `"]"') fmt(3))) star(+ 0.10 * 0.05 ** 0.01 *** 0.001) b(%9.3f) ///
	noobs nonotes nonumbers  ///
	stats(ajr2  N, labels("Adjusted R^2" "N") fmt(3 0)) varlabels(_cons Constant) ///
	refcat(2.treat "\forceindent Baseline")   ///
	rename(1.treat "\textbf{Treatment condition}") ///
	mtitles("India" ///
	"South Africa" "US") replace
	

* Matrix 
mat D = 1,0.9,A[1,1],A[5,1],A[6,1]\			/// 
		2,1.0,A[1,2],A[5,2],A[6,2]\			///
		3,1.1,A[1,3],A[5,3],A[6,3]\			///
		1,1.9,B[1,1],B[5,1],B[6,1]\			/// 
		2,2.0,B[1,2],B[5,2],B[6,2]\			///
		3,2.1,B[1,3],B[5,3],B[6,3]\			///
		1,2.9,C[1,1],C[5,1],C[6,1]\			/// 
		2,3.0,C[1,2],C[5,2],C[6,2]\			///
		3,3.1,C[1,3],C[5,3],C[6,3]			

		
mat list D	


frame create plot1
cwf plot1		
svmat D
rename D1 treatment						// 1 = Control, 2 = Intergroup, 3 = Interpersonal
rename D2 Xpos							// Position on X-axis
rename D3 b								// Parameter estimate (Marginal effect)
rename D4 ll							// lower confidence level
rename D5 ul							// upper confidence level


* Plot Figure 1: 
tw ///
	(rspike ll ul Xpos if treatment == 1, lc(gs10)) ///
	(rspike ll ul Xpos if treatment == 2, lc(black)) ///
	(rspike ll ul Xpos if treatment == 3, lc(black)) ///
	(scatter b Xpos if treatment == 1, msym(D) mc(gs10) msize(med)) ///
	(scatter b Xpos if treatment == 2, msym(O) mc(black) msize(med)) ///
	(scatter b Xpos if treatment == 3, msym(O) mc(black) mfcolor(white) msize(med)) ///
	, yscale(range(-0.22 0.42) extend lc(none)) ytit("% Mentioning a Word" "related to Intergroup Ineq.", size(medsmall)) ///
	yline(0) ylab(-0.2 -0.1 0 0.1 0.2 0.3 0.4, labsize(small) gstyle(solid) glc(gs15%30) notick) ///
	xscale(range(.5 3.5) extend) xtit("Country", size(medsmall)) ///
	xlab(1 "India" 2 "South Africa" 3 "United States", labsize(small) gstyle(solid) glc(gs15%30) notick) ///
	legend(pos(7) ring(0) order(4 "Control Group" 5 "Intergroup Inequality" 6 "Interpersonal Inequality") size(vsmall)) ///
	plotregion(lcolor(black) lwidth(medium)) ///
	tit("{bf:(A)} Intergroup ineq. dictionary", pos(11) justification(left) size(med)) ///
	scale(1.3) graphregion(m(small)) ///
	name(dist_fair, replace)

graph display, xsize(12) ysize(8) 
graph export "output/figure1.pdf", as(pdf) replace
	
	